home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT04.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.6 KB  |  113 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 4                          
  5.                                           
  6.  This program has several loops which perform a drawing action until you      
  7.  press a key.                                                                 
  8.                                           
  9.  The following graphics primitives are demonstrated: wline, wfline,           
  10.  wrectangle, wbar, wcircle, wfill_circle, wellipse, wfill_ellipse,            
  11.  wstyleline, and wbutt.                                                       
  12.                                           
  13.  *** PROJECT ***                                                             
  14.  This program requires the file WGT5_WC.LIB to be linked.                    
  15.                                           
  16.  *** DATA FILES ***                                                          
  17.  NONE                                                                        
  18.                                WATCOM C++ VERSION 
  19. ==============================================================================
  20. */
  21.  
  22. #include <conio.h>
  23. #include <wgt5.h>
  24.  
  25. #define MAX_RADIUS 100
  26.  
  27. void main(void)
  28. {
  29.   color pal[256];
  30.   short x, y, x2, y2, col, ctr;
  31.   short oldmode;
  32.  
  33.   printf ("WGT Example #4\n\n");
  34.   printf ("This program will randomly paste things on the screen using 10 different\n");
  35.   printf ("WGT commands. Press a key to end each section.\n");
  36.   printf ("\n\nPress any key to continue.\n");
  37.   getch ();
  38.  
  39.   if ( !vgadetected() )
  40.   {
  41.     printf("Error - VGA card required for any WGT program.\n");
  42.     exit (0);
  43.   }
  44.  
  45.   oldmode = wgetmode ();        /* Preserve initial video mode */
  46.   vga256 ();                    /* Start graphics mode */
  47.  
  48.   wtextcolor (15);              /* Text will be white */
  49.   ctr = 0;                      /* Start counter for first primitive */
  50.  
  51.   do {
  52.     wclip (0, 0, 319, 199);                     /* Clip to full screen */
  53.     wouttextxy (230, 0, NULL, "WGT DEMO 4");    /* Display text */
  54.     switch (ctr)                                /* Show primitive type */
  55.     {
  56.       case 0 : wouttextxy (0, 0, NULL, "Now using WLINE"); 
  57.            break;
  58.       case 1 : wouttextxy (0, 0, NULL, "Now using WFLINE"); 
  59.            break;
  60.       case 2 : wouttextxy (0, 0, NULL, "Now using WRECTANGLE"); 
  61.            break;
  62.       case 3 : wouttextxy (0, 0, NULL, "Now using WBAR"); 
  63.            break;
  64.       case 4 : wouttextxy (0, 0, NULL, "Now using WCIRCLE"); 
  65.            break;
  66.       case 5 : wouttextxy (0, 0, NULL, "Now using WFILL_CIRCLE"); 
  67.            break;
  68.       case 6 : wouttextxy (0, 0, NULL, "Now using WELLIPSE"); 
  69.            break;
  70.       case 7 : wouttextxy (0, 0, NULL, "Now using WFILL_ELLIPSE"); 
  71.            break;
  72.       case 8 : wouttextxy (0, 0, NULL, "Now using WSTYLELINE"); 
  73.            break;
  74.       case 9 : wouttextxy (0, 0, NULL, "Now using WBUTT"); 
  75.            wreadpalette (0, 255, pal);        /* Load current palette */
  76.            wsetrgb (253, 60, 60, 60, pal);    /* Alter last 3 entries */
  77.            wsetrgb (254, 50, 50, 50, pal);
  78.            wsetrgb (255, 40, 40, 40, pal);
  79.            wsetpalette (0, 255, pal);         /* Set new palette */
  80.            break;
  81.       
  82.     }
  83.     wclip (0, 8, 319, 199);         /* Clip all primitives below text line */
  84.  
  85.     do {
  86.       x = rand () % 320;         /* Randomize first point  -  (x,y)   */
  87.       y = rand () % 200;
  88.       x2 = rand () % 320;        /* Randomize second point -  (x2,y2) */
  89.       y2 = rand () % 200;
  90.       col = rand () % 256;       /* Pick a color index to use */
  91.       wsetcolor (col);           /* Now use it */
  92.       switch (ctr)               /* Perform primitive */
  93.       {
  94.     case 0 : wline (x, y, x2, y2); break;
  95.     case 1 : wfline (x, rand() % 192 + 8, x2, rand() % 192 + 8); break;
  96.     case 2 : wrectangle (x, y, x2, y2); break;
  97.     case 3 : wbar (x, y, x2, y2); break;
  98.     case 4 : wcircle (x, y, rand() % MAX_RADIUS); break;
  99.     case 5 : wfill_circle (x, y, rand() % 100); break;
  100.     case 6 : wellipse (x, y, rand() % MAX_RADIUS, rand() % MAX_RADIUS); break;
  101.     case 7 : wfill_ellipse (x, y, rand() % MAX_RADIUS, rand() % MAX_RADIUS); break;
  102.     case 8 : wstyleline (x, rand() % 192 + 8, x2, rand() % 192 + 8, rand() ); break;
  103.     case 9 : wbutt (x, y, x2, y2); break;
  104.       }
  105.     } while (!kbhit ());        /* Stop when key is pressed */
  106.     getch ();                   /* Get key from buffer */
  107.     wcls (0);                   /* Clear screen with black */
  108.     ctr++;                      /* Increment counter to next primitive */
  109.   } while (ctr < 10);           /* Have we done all 10 ? */
  110.  
  111.   wsetmode (oldmode);           /* Restore initial video mode */
  112. }
  113.